#include "udp_socket.hpp"
#define CHECE_ERS(q) if((q)==false){return -1;}

int main(int argc,char* argv[])
{
  if(argc!=3)
  {
    std::cout<<"Usage :./udp_cli 192.168.12 9000"<<std::endl;
    std::cout<<"Server Address!"<<std::endl;
      return -1;
  }
  std::string srv_ip=argv[1];
  int srv_prot=std::stoi(argv[2]);


  UdpSocket sock;
  CHECE_ERS(sock.Socket());

  //客户端不推荐主动绑定字符串
  while(1)
  {
    std::cout<<"client say:";
    fgetc(stdout);
    std::string buf;
    std::cin>>buf;
    CHECE_ERS(sock.Send(buf,srv_ip,srv_prot));
    
    buf.clear();
    CHECE_ERS(sock.Recv(&buf));
    std::cout<<"server say:"<<buf;
  }
  CHECE_ERS(sock.Close());
  return true;

}
